public class QuarterlyPlan{
   private final int SUN=0,MON=1,TUE=2,WED=3,THU=4,FRI=5,SAT=6,START=0,END=1;
   QuarterlyPlan(){}

   public String[] quarterPlan1(String selection[], ObjOffering off[], int avail[][]){
      String plan[] = null;
      MySet set = new MySet();
      for(int i=0; i<selection.length; ++i){
         for(int j=0; j<off.length; ++j){
            int cnt=0;
            for(int k=0; k<avail.length; ++k){
               if(selection[i].equals(off[j].courseid) && avail[k][START]<=off[j].days[k][START] && avail[k][END]>=off[j].days[k][END]){
                  ++cnt;
               }
            }//k loop - days
            if(cnt==7)
               set.add(selection[i]);
         }//j loop - offering list
      }//i loop - selection
      plan = set.toArray();
      if(plan==null){
         return null;
      }
      ObjOffering datacollect[] = new ObjOffering[plan.length];
      for(int i=0; i<plan.length; ++i){
         for(int j=0; j<off.length; ++j){
            if(plan[i].equals(off[j].courseid)){
               datacollect[i] = off[j];
            }
         }
      }
      set = new MySet();
      if(datacollect[0]!=null)
        set.add(datacollect[0].courseid);
      
      for(int i=1; i<datacollect.length; ++i){
         int cnt=0;
         for(int j=0; j<i; ++j){
            
            if(i!=j){
               for(int k=0; k<datacollect[i].days.length; ++k){
                  if(datacollect[j].days[k][START]==2400 || datacollect[i].days[k][START]==2400){
                     ++cnt;
                  }else{
                     if( (datacollect[j].days[k][START]<=datacollect[i].days[k][START] && datacollect[j].days[k][END]<=datacollect[i].days[k][START]) ||
                        (datacollect[j].days[k][START]>=datacollect[i].days[k][END] && datacollect[j].days[k][END]>=datacollect[i].days[k][END])){
                        ++cnt;
                     }
                  }
               }//k
            }
            
         }//j
         if(cnt==i*7){
               set.add(datacollect[i].courseid);
            }
      }//i
/*
      for(int i=0; i<datacollect.length; ++i){
         for(int j=0; j<i+1; ++j){
            if(i!=j){
               int cnt=0;
               for(int k=0; k<datacollect[i].days.length; ++k){
                  if(datacollect[i].days[k][START]==2400 && datacollect[j].days[k][START]==2400){
                     ++cnt;
                  }else{
                     if( (datacollect[j].days[k][START]<=datacollect[i].days[k][START] && datacollect[j].days[k][END]<=datacollect[i].days[k][START]) ||
                        (datacollect[j].days[k][START]>=datacollect[i].days[k][END] && datacollect[j].days[k][END]>=datacollect[i].days[k][END])){
                        ++cnt;
                     }else{
                        break;
                     }
                  }
               }//k loop - days.length
               if(cnt==7){
                  set.add(datacollect[j].courseid);
               }
            }
         }//j loop - datacollect.length
      }//i loop - datacollect.length
*/      
      return set.toArray();
   }
   
   
   
   
   //
   private class MySet{
      String set = "";
      String deliminate_symbol = ", ";

      MySet(){}
      MySet(String s){ deliminate_symbol = s; }

      //returns the number of elements added to the set
      public int add(String s){
         if(set.length()==0 && s.compareTo("")!=0){
            set += s;
            return 1;
         }else{
            String temp[] = set.split(deliminate_symbol);
            boolean found = false;
            for(int i=0; i<temp.length; ++i)
               if(temp[i].compareTo(s)==0)
                  found = true;
            if(!found && s.compareTo("")!=0){
               set += deliminate_symbol+s;
               return 1;
            }
         }
         return 0;
      }
   
      //sort the list (ASC)
      private String reorder(String s){
         String temp[] = set.split(deliminate_symbol);
         java.util.Arrays.sort(temp);
         String str = "";
         for(int i=0; i<temp.length; ++i){
            if(str.length()==0){
               str += temp[i];
            }else{
               str += deliminate_symbol+temp[i];
            }
         }
         return str;
      }
   
      //returns the number of elements removed from the set
      public int remove(String s){
         if(set.length()>0){
            String temp[] = set.split(deliminate_symbol);
            boolean found = false;
            for(int i=0; i<temp.length; ++i){
               if(temp[i].compareTo(s)==0){
                  temp[i] = "";
                  found = true;
                  break;
               }
            }
            set = "";
            if(temp.length>1 && temp[0].compareTo("")==0){
               for(int i=1; i<temp.length; ++i){
                  if(i==1)
                     set += temp[i];
                  else
                     set += deliminate_symbol+temp[i];
               }
            }else if(temp.length>1){
               set += temp[0];
               for(int i=1; i<temp.length; ++i)
                  if(temp[i].compareTo("")!=0)
                     set += deliminate_symbol+temp[i];
            }
            if(found)
               return 1;
         }
         return 0;
      }
   
      //return true if both sets have all of the same elements (order does not matter)
      public boolean isEqual(MySet s){
         String left[], right[];
         left = set.split(deliminate_symbol);
         right = s.set.split(deliminate_symbol);
         if(left.length!=right.length)
            return false;
         int cnt = 0;
         for(int i=0; i<left.length; ++i){
            for(int j=0; j<right.length; ++j){
               if(left[i].compareTo(right[j])==0){
                  ++cnt;
               }
            }
         }
         if(cnt!=left.length)
            return false;
         return true;
      }
   
      //returns true if left-hand side (set) is a subset of right-hand side (set)
      public boolean isSubset(MySet s){
         String left[], right[];
         left = set.split(deliminate_symbol);
         right = s.set.split(deliminate_symbol);
         if(left.length>right.length)
            return false;
         int cnt = 0;
         for(int i=0; i<left.length; ++i){
            for(int j=0; j<right.length; ++j){
               if(left[i].compareTo(right[j])==0){
                  ++cnt;
               }
            }
         }
         if(cnt!=left.length)
            return false;
         return true;
      }
   
      //returns the left-hand side (set) subtracted by the right-hand side
      public MySet minus(MySet s){
         String left[], right[];
         left = set.split(deliminate_symbol);
         right = s.set.split(deliminate_symbol);
         for(int i=0; i<right.length; ++i){
            for(int j=0; j<left.length; ++j){
               if(right[i].compareTo(left[j])==0){
                  left[j] = "";
               }
            }
         }
         MySet temp = new MySet();
         for(int i=0; i<left.length; ++i){
            temp.add(left[i]);
         }
         return temp;
      }
   
      //returns the union of left-hand (set) with right-hand (set) [only unique elements]
      public MySet join(MySet s){
         MySet temp = new MySet(set);
         String left[] = s.set.split(deliminate_symbol);
         for(int i=0; i<left.length; ++i)
            temp.add(left[i]);
         return temp;
      }
   
      //returns the first elememt in the list
      public String getFirstElem(){
         String temp[] = toArray();
         return temp[0];
      }
      
      public String[] toArray(){ return set.split(deliminate_symbol); }
      public String getSet(){ return set; }
      public String getDelimSymbol(){ return deliminate_symbol; }
      public void removeAll(){ set = ""; }
   
      public void printSet(){ qp("{"+set+"}"); }
      public void qp(String  p){ System.out.println(p); }
      public void qp(int     p){ System.out.println(p); }
      public void qp(boolean p){ System.out.println(p); }
      public void qp(MySet   p){ System.out.println(p.set); }
   }
}